package com.ganee.agora.adapter

import android.text.TextUtils
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.chad.library.adapter.base.BaseQuickAdapter
import com.ganee.agora.R
import com.ganee.agora.manager.RecyclerViewHolder
import com.ganee.agora.model.InsertActivityEntity
import com.ganee.agora.widget.ratingbar.AndRatingBar


/**
 *    @author : EricCui
 *    date   : 2020-01-01 17:52
 *    desc   :  your event adapter
 */

class YourEventAdapter(entityList: MutableList<InsertActivityEntity>) : BaseQuickAdapter<InsertActivityEntity,
        RecyclerViewHolder>(R.layout.item_recyclerview_your_event, entityList) {


    override fun convert(helper: RecyclerViewHolder, item: InsertActivityEntity?) {
        if (item != null) {
            val icon = helper.getView<ImageView>(R.id.item_list_iv_icon) as ImageView
            Glide.with(mContext)
                    .load(item.activePic)
                    .diskCacheStrategy(DiskCacheStrategy.NONE)
                    .placeholder(R.drawable.home_placeholder)
                    .error(R.drawable.home_placeholder)
                    .into(icon)

            val ratingBar = helper.getView<AndRatingBar>(R.id.item_list_iv_rank) as AndRatingBar
            if (!TextUtils.isEmpty(item.score)){
                ratingBar.rating = item.score!!.toFloat()
            }
            helper.setText(R.id.item_list_tv_title, item.eventTitle)
            if (null != item.amount && !TextUtils.isEmpty(item.amount) && item.amount!!.toDouble() > 0){
                helper.setText(R.id.item_list_tv_money, item.amount)
            } else {
                helper.setText(R.id.item_list_tv_money, "Free")
            }
        }
    }
}